package com.example.settings;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 配置swagger
 */
@Configuration
public class SwaggerSettings {

    @Bean
    public Docket docket(){
        //创建docket对象，指定文档类型（使用swagger2版本）
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        //创建ApiInfo对象
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("自我测试") //api接口文档标题
                .version("1.0") //版本
                .description("项目的技术栈：前端是Vue3,JavaScript,ES6,CSS,Axios + <br/>" +
                        "后端 SpringBoot2 , MyBatis-Plus , Hikari连接池， Redis，Thymeleaf")
                         //文档描述
                .contact(new Contact("wyt","http://www.baidu.com","aa@a.com")) //联系人
                .build();
        //设置docket使用apiinfo
        docket = docket.apiInfo(apiInfo);


        //指定参与文档生成的包或者controller
        docket  = docket.select().apis(
                   RequestHandlerSelectors.basePackage("com.example.controller"))
                  .build();

        //停用swagger
        //docket.enable(false);

        return docket;
    }
}
